from django.shortcuts import render

# Create your views here.
from rest_framework.response import Response
from .ser import *
from rest_framework.views import APIView
# class ZhuceAPIView(APIView):
#     def post(self,request):


class XiaoqvAPIView(APIView):
    def get(self,request):
        data = Xiaoqv.objects.all()
        ser = XiaoqvSer(data,many=True)
        return Response(ser.data)
    def post(self,request):
        data = request.data
        ser = XiaoqvSer(data=data)
        ser.is_valid(raise_exception=True)
        ser.save()
        return Response(ser.data)
class BanjiAPIView(APIView):
    def get(self,request):
        xiaoqv_id = request.GET.get('xiaoqv_id')
        if xiaoqv_id:
            page = Banji.objects.filter(xiaoqv_id=xiaoqv_id)
        else:
            page = Banji.objects.all()
        ser = BanjiSer(page,many=True)
        return Response(ser.data)
    def post(self,request):
        pass